<template>
  <div>
    <el-row style="padding:0" type="flex" justify="space-between">
      <el-col  class="exam-container">
        <div class="exam-header">
          <div>测试</div>
          <div class="user-scole">
            <span>你的积分为:</span>
            <span>{{roles.userAverageScore}}</span>
            <div class="rank-container">
              <el-table :data="tableData" style="width: 100%">
                <el-table-column type="index" label="排名" ></el-table-column>
                <el-table-column prop="username" label="用户名" ></el-table-column>
                <el-table-column prop="userAverageScore" label="积分"></el-table-column>
              </el-table>
            </div>
          </div>
        </div>

        <div v-for="exam in examination" :key="exam.index" @click="into(exam.number)">
          <el-row class="examination">
            <el-col :span="18">
              <span>{{exam.examinationName}}</span>
            </el-col>
            <el-col :span="6" style="text-align:right">{{exam.startTime}}</el-col>
          </el-row>
        </div>
      </el-col>
    </el-row>
  </div>
</template>
<script>
import {mapGetters} from "vuex"
import { queryAll } from "@/api/examination";
import { showRank } from "@/api/examination_detail";
export default {
  data() {
    return {
      examination: "",
      tableData: [],
    };
  },
  computed:{ 
    ...mapGetters([
      'roles'
    ])
  },
  created() {
    this.query();
  },
  methods: {
    query() {
      queryAll().then((res) => {
        this.examination = res.data.examination;
      });
      showRank().then((res) => {
        this.tableData = res.data.userList;
      });
    },
    into(id) {
      this.$router.push({
        path: "/exam/detail",
        query: {
          id,
        },
      });
    },
  },
};
</script>
<style>
.examination {
  border-bottom: solid 1px rgb(253, 247, 247);
  padding: 20px;
}
.examination:hover {
  color: rgb(119, 166, 253);
  cursor: pointer;
}
.exam-container {
  overflow: hidden;
  border-radius: 15px;
  border: solid 1px rgb(119, 166, 253);
}
.rank-container .el-table td{
 
  border: none;
  background: rgba(119, 166, 253, 0.37);
}
.rank-container .el-table th{
  border: none; 
  font-weight: 600;
  font-size: 1.1rem;
  background: rgba(119, 166, 253, 0.37);
}
.exam-header {
  cursor: pointer;
  position: relative;
  font-weight: 600;
  color: #fff;
  font-size: 1.2rem;
  height: 3rem;
  line-height: 3rem;
  text-align: center;
  background: rgb(119, 166, 253);
}
.user-scole {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 10;
  font-weight: 600;
  color: #fff;
  font-size: 1.2rem;
  height: 3rem;
  line-height: 3rem;
  text-align: center;
  background: rgb(119, 166, 253);
  transition: ease-in 0.3s;
  transform: scaleY(0);
  transform-origin: top;
  opacity: 0;
}
.exam-header:hover .user-scole {
  transform: scaleY(1);
  opacity: 1;
}
</style>